import type {
  Exposed as ImgCropModalExposed,
  Options as ImgCropOptions,
} from './index.vue'

import { inject, type InjectionKey, provide, ref, type Ref } from 'vue'

export { default as ImgCropModal } from './index.vue'

interface ImgCropContext {
  imgCropModalRef: Ref<ImgCropModalExposed | undefined>
}
const imgCropKey: InjectionKey<ImgCropContext> = Symbol('img-crop')
function createImgCropContext() {
  const imgCropModalRef = ref<ImgCropModalExposed>()

  provide(imgCropKey, {
    imgCropModalRef,
  })
  return {
    imgCropModalRef,
  }
}
function useImgCropContext() {
  return inject(imgCropKey)
}

export {
  createImgCropContext,
  type ImgCropModalExposed,
  type ImgCropOptions,
  useImgCropContext,
}
